home *** CD-ROM | disk | FTP | other *** search
- unit LossU;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, DB, DBTables;
-
- type
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- private
- { Private declarations }
- public
- procedure DoIdle(Sender: TObject; var Done: Boolean);
- {$ifdef VER80}
- procedure WMEndSession(var Msg: TWMEndSession);
- message wm_EndSession;
- {$endif}
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- DbiProcs;
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.OnIdle := DoIdle;
- end;
-
- procedure TForm1.DoIdle(Sender: TObject; var Done: Boolean);
- begin
- { Each idle period, write a dirty buffer to disk }
- DbiUseIdleTime;
- Done := True;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- var
- Loop: Integer;
- begin
- { Generic way of ensuring all }
- { table changes are saved }
- { when the form is closed }
- for Loop := 0 to ComponentCount - 1 do
- if Components[Loop] is TDataSet then
- with TDataSet(Components[Loop]) do
- if State in dsEditModes then
- Post;
- end;
-
- {$ifdef VER80}
- procedure TForm1.WMEndSession(var Msg: TWMEndSession);
- begin
- { If session is ending, call Halt }
- { to get exit routines executed. }
- { The DB unit's exit routine frees }
- { the Session object, which will }
- { unload the BDE, flushing }
- { any unsaved changes to disk }
- if Msg.EndSession then
- Halt;
- end;
- {$endif}
-
- end.
-